#include "fxcc/json/Serializer.h"
#include "fxcc/core/graph/common/MSDF.h"

using namespace fxcc::json;
using namespace fxcc::graph::common;

template<>
bool Serializer::Decode<MSDFConfig::Altas>(const nlohmann::json& j, MSDFConfig::Altas& e)
{
    GetVariable<std::string>(j, "type", e.type);
    GetVariable<int>(j,"distanceRange",e.distanceRange);
    GetVariable<int>(j, "distanceRangeMiddle", e.distanceRangeMiddle);
    GetVariable<int>(j, "size", e.size);
    GetVariable<int>(j, "width", e.width);
    GetVariable<int>(j, "height", e.height);
    GetVariable<std::string>(j, "yOrigin", e.yOrigin);
    return true;
}


template<>
bool Serializer::Decode<MSDFConfig::Metrics>(const nlohmann::json& j, MSDFConfig::Metrics& e)
{
    GetVariable<int>(j, "emSize", e.emSize);
    GetVariable<float>(j, "lineHeight", e.lineHeight);
    GetVariable<float>(j, "ascender", e.ascender);
    GetVariable<float>(j, "descender", e.descender);
    GetVariable<float>(j, "underlineY", e.underlineY);
    GetVariable<float>(j, "underlineThickness", e.underlineThickness);
    return true;
}

template<>
bool Serializer::Decode<MSDFConfig::Bounds>(const nlohmann::json& j, MSDFConfig::Bounds& e)
{
    GetVariable<float>(j, "left",e.left);
    GetVariable<float>(j, "bottom", e.bottom);
    GetVariable<float>(j, "right", e.right);
    GetVariable<float>(j, "top", e.top);
    return true;
}


template<>
bool Serializer::Decode<MSDFConfig::GlyphInfo>(const nlohmann::json& j, MSDFConfig::GlyphInfo& e)
{
    GetVariable<int>(j,"unicode",e.unicode);
    GetVariable<float>(j, "advance", e.advance);
    GetVariable<MSDFConfig::Bounds>(j, "planeBounds", e.planeBounds);
    GetVariable<MSDFConfig::Bounds>(j, "atlasBounds", e.atlasBounds);
    return true;
}


template<>
bool Serializer::Decode<MSDFConfig::KerningPair>(const nlohmann::json& j, MSDFConfig::KerningPair& e)
{
    GetVariable<int>(j, "unicode1", e.unicode1);
    GetVariable<int>(j, "unicode2", e.unicode2);
    GetVariable<float>(j, "advance", e.advance);
    return true;
}

template<>
bool Serializer::Decode<MSDFConfig>(const nlohmann::json& j, MSDFConfig& e)
{
    GetVariable<MSDFConfig::Altas>(j, "atlas", e.altas);
    GetVariable<MSDFConfig::Metrics>(j, "metrics", e.metrics);
    GetArrayVariable<MSDFConfig::GlyphInfo>(j, "glyphs", e.glyphs);
    GetArrayVariable<MSDFConfig::KerningPair>(j, "kerning", e.kerning);
    return true;
}